package com.apop.accompany.stuff.service.impl;

import com.apop.accompany.auth.entity.User;
import com.apop.accompany.stuff.entity.Stuff;
import com.apop.accompany.stuff.mapper.StuffMapper;
import com.apop.accompany.stuff.service.StuffService;
import com.apop.common.model.PageResult;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author JiayiZheng
 * @since 2024-10-05
 */
@Service
public class StuffServiceImpl extends ServiceImpl<StuffMapper, Stuff> implements StuffService {

    @Override
    public List<Stuff> getAll() {
        return baseMapper.selectList(null);
    }

    @Override
    public Stuff getById(Integer id) {
        return baseMapper.selectById(id);
    }

    @Override
    public int update(Stuff stuff) {
        return baseMapper.updateById(stuff);
    }

    @Override
    public int deleteById(Integer id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public int deleteBatch(List<Integer> ids) {
        if (ids == null || ids.isEmpty()) {
            return 0;
        }
        return baseMapper.deleteBatchIds(ids);
    }

    @Override
    public PageResult getList(Integer pageNum, Integer pageSize) {
        //        开启分页查询,当执行查询时，插件进行相关的sql拦截进行分页操作，返回一个page对象
        Page<User> page = PageHelper.startPage(pageNum, pageSize);
        baseMapper.selectList(null);
        PageResult pageResult = new PageResult(page.getResult(), page.getTotal());
        return pageResult;
    }
}
